<script setup>
import { useRouter, useRoute } from 'vue-router'
import { reactive, ref } from 'vue'
import { request } from "@/utils"
import { Toast } from 'vant'

const form = reactive({
    username: '',
    password: ''
})
const router = useRouter()
const myform = ref(null)
const onSubmit = async function () {
    const { data } = await request.post('/user/reg', {
        username: form.username,
        password: form.password
    })
    if (data.code === 200) {
        Toast.success('增加成功')
        router.push('menu')
    }

}

const onClickLeft = function () {
    router.go(-1)
}
</script>
<template>
    <div>
        <van-nav-bar title="新增会员" left-text="菜单功能" left-arrow @click-left="onClickLeft" class="vipnav"
            :border="false" />
        <van-form @submit="onSubmit" ref="myform">
            <van-cell-group inset>
                <van-field v-model="form.username" name="用户名" label="用户名" placeholder="用户名"
                    :rules="[{ required: true, message: '请填写用户名' }]" />
                <van-field v-model="form.password" type="password" name="密码" label="密码" placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    新增会员
                </van-button>
            </div>
        </van-form>
    </div>
</template>
<style lang="scss">
.vipnav {
    .van-nav-bar__title {
        color: #fff;
    }

    background-color: deepskyblue;

    .van-nav-bar__text {
        color: #fff;
    }

    .van-icon:before {
        color: #fff;
    }
}
</style>